#include "head.h"


int main(int argc, char *argv[]){                                  

    ARGS_CHECK(argc, 3);

    int sockfd = establishConnect(argv[1], argv[2]);

    // 身份验证
    idVerify(sockfd);
    // 身份验证通过的逻辑
    fd_set fset;
    char instruct[1024];
    while(1){
        FD_ZERO(&fset);
        FD_SET(sockfd, &fset);
        FD_SET(STDIN_FILENO, &fset);
        
        int ret = select(sockfd + 1, &fset, NULL, NULL, NULL);
        if(ret <= 0){
            printf("connection disconnected\n");
            break;
        }
        // 采用一问一答的通信模式
        if(FD_ISSET(STDIN_FILENO, &fset)){
            printf("have mess\n");
            bzero(instruct, sizeof(instruct));
            read(STDIN_FILENO, instruct, sizeof(instruct));
            // 处理此次键盘输入
            dealInstruction(instruct, sockfd);
        }

    }
    
    close(sockfd);
    return 0;
}

